from base import _YamlHelper, build_driver
from page import Page


class BackgroundLoginPage(Page):
    background_login_yaml = _YamlHelper().get_config_as_dict('niushop23\\page\\background_login.yaml')[
        'BackgroundLoginPage']

    def back_login(self, name, pwd):
        '''
        后台登录输入账户密码
        :param name: 输入账户名称
        :param pwd:  输入密码
        :return:
        '''
        driver = self._driver
        driver.type(self.background_login_yaml['BACKGROUND_LOGIN_ID'], name)
        driver.type(self.background_login_yaml['BACKGROUND_LOGIN_PWD'], pwd)
        driver.click(self.background_login_yaml['BACKGROUND_LOGIN_BUTTON'])

    def back_loginout(self):
        '''
        退出登录
        :return:
        '''
        driver = self._driver
        driver.click(self.background_login_yaml['BACKGROUND_LOGINOUT_BUTTON'])

    def user_name_text(self):
        '''
        获取用户名文本
        :return:
        '''
        driver = self._driver
        admin_name = driver.get_text(self.background_login_yaml['USER_NAME_TEXT'])
        return admin_name

    def hint_fail_text(self):
        '''
        获取登录失败提示文本
        :return:
        '''
        driver = self._driver
        hint_text = driver.get_text(self.background_login_yaml['HINT_FAIL_TEXT'])
        return hint_text


if __name__ == '__main__':
    driver = build_driver('http://www.localhost/niushop/admin','c')
    backlogin = BackgroundLoginPage(driver)
    backlogin.back_login('admin','123456')

